import matplotlib.pyplot as plt
import numpy as np
import math
a = [0,1,3,3,2,2,4,3]
a = np.array(a)
 
# 坐标旋转
# 绕pointx,pointy逆时针旋转
def Nrotate(angle,valuex,valuey,pointx,pointy):
  angle = math.radians(angle) #角度
  valuex = np.array(valuex)
  valuey = np.array(valuey)
  nRotatex = (valuex-pointx)*math.cos(angle) - (valuey-pointy)*math.sin(angle) + pointx
  nRotatey = (valuex-pointx)*math.sin(angle) + (valuey-pointy)*math.cos(angle) + pointy
  return nRotatex, nRotatey
# 绕pointx,pointy顺时针旋转
def Srotate(angle,valuex,valuey,pointx,pointy):
  angle = math.radians(angle) #角度
  valuex = np.array(valuex)
  valuey = np.array(valuey)
  sRotatex = (valuex-pointx)*math.cos(angle) + (valuey-pointy)*math.sin(angle) + pointx
  sRotatey = (valuey-pointy)*math.cos(angle) - (valuex-pointx)*math.sin(angle) + pointy
  return sRotatex,sRotatey
 
for i in range(0,360):
    Pointx ,Pointy = Srotate(i,a[0:4],a[4:8],0,0)

    plt.plot(a[0:4],a[4:8],color='red')
    plt.plot(Pointx,Pointy,color='green')

    # 坐标居中
    plt.xticks(np.arange(-5,5,0.5))
    plt.yticks(np.arange(-5,5,0.5))

    plt.pause(0.1)
  
plt.show()